     # coding : UTF-8
import threading
import re
import time
import urllib
import urllib.request
import string

res_a = 0
res_b = 0
res_c = 0

def get_html_text(url):
    global res_a
    global res_b
    global res_c

    headers = {'User-Agent': 'Mozilla/5.0 (Windows NT 6.1; WOW64; rv:23.0) Gecko/20100101 Firefox/23.0'}
    request = urllib.request.Request(url=url, headers=headers)
    html = urllib.request.urlopen(request).read()

    html = html.decode('utf-8')

    #reg = r'<div class="estimatedchart hasLoading"> <img src="(.+?\.png)'
    reg = r'(http://j4.dfcfw.com/charts/pic6/.+?\.png)'
    name = r'http://j4.dfcfw.com/charts/pic6/(.+?\.png)'

    imgre = re.compile(reg)
    namere=re.compile(name)
    url_list = re.findall(imgre, html)
    name_list = re.findall(namere, html)

    title = re.findall(re.compile(r'funCur-FundName">(.+?)</span>'), html)
    ret1 = re.findall(re.compile(r'id="gz_gszzl">(.+?)%</span>'), html)
    ret2 = re.findall(re.compile(r'id="gz_gsz">(.+?)</span>'), html)
    print(title[0], end=" ")
    print(ret1[0], end=" ")
    print(ret2[0], end=" ")
    print(url_list[0])
    urllib.request.urlretrieve(url_list[0], './download/%s' % name_list[0])

if __name__ == '__main__':
    for i in [110022,1542,968010]:#range(0, 999999):#
        try:
            get_html_text("http://fund.eastmoney.com/%06d.html" %i)
        except Exception as e:
            continue